<?php
$a_tablecolumns_namhoa_system_option = array(
    'name'    => 'system_option',
    'columns' => array(
        'option_id'     ,
        'option_type'   ,
        'option_status' ,
        'option_key'    ,
        'option_data'   ,
    ),
);

function get_columns_namhoa_system_option() {
    return array(
        'name'    => 'system_option',
        'columns' => array(
            'option_id'     ,
            'option_type'   ,
            'option_status' ,
            'option_key'    ,
            'option_data'   ,
        ),
    );
}

$f_option_id     = 0 ;
$f_option_type   = '';
$f_option_status = '';
$f_option_key    = '';
$f_option_data   = '';
$f_creatorid     = '';
$f_updaterid     = '';
$f_insertdate    = date('Y-m-d H:i:s');
$f_updatedate    = $f_insertdate;

class namhoa_system_option {
    public function __get($v_property) {
        return '';
    }
} 

$d_system_option = new namhoa_system_option();

if (isset($_REQUEST['option_id'     ] )) { $f_option_id     = $_REQUEST['option_id'     ] ; }
if (isset($_REQUEST['option_type'   ] )) { $f_option_type   = $_REQUEST['option_type'   ] ; }
if (isset($_REQUEST['option_status' ] )) { $f_option_status = $_REQUEST['option_status' ] ; }
if (isset($_REQUEST['option_key'    ] )) { $f_option_key    = $_REQUEST['option_key'    ] ; }
if (isset($_REQUEST['option_data'   ] )) { $f_option_data   = $_REQUEST['option_data'   ] ; }

function make_filter_namhoa_system_option($s_field, $s_keyword) {
    $v_filter = '';

    if ($s_field != '' && $s_keyword != '') {
        switch ($s_field) {
            case 'option_type'   :
            case 'option_status' :
            case 'option_key'    :
            case 'option_data'   :
            case 'option_id'     :
                $v_filter = "`$s_field` like '%$s_keyword%'";

                break;

        }
    }

    return $v_filter;
}

function make_advanced_filter_namhoa_system_option($s_field, $s_keyword) {
    $v_filter = '';

    if ($s_field != '' && $s_keyword != '') {
        switch ($s_field) {
            case 'option_type'   :
            case 'option_status' :
            case 'option_key'    :
            case 'option_data'   :
                $v_filter = "`$s_field` like '%$s_keyword%'";

                break;

            case 'option_id'     :
                if (strpos($s_keyword, '~') !== FALSE) {
                    list($v_from, $v_to) = explode('~', $s_keyword, 2);
                
                    if (is_numeric($v_from)) {
                        $v_filter = $v_filter . "`$s_field` >= $v_from";
                    }
                
                    if (is_numeric($v_to)) {
                        $v_filter = $v_filter . (empty($v_filter) ? '' : ' and ') . "`$s_field` <= $v_to";
                    }
                
                    $v_filter = empty($v_filter) ? '' : "($v_filter)";
                }
                elseif (is_numeric($s_keyword)) {
                    $v_filter = "`$s_field` = $s_keyword";
                }

                break;

        }
    }

    return $v_filter;
}

function build_filter_namhoa_system_option($s_field) {
    echo '<option value="option_id"'     , ($s_field == 'option_id'      ? ' selected="selected"' : ''), '> Option ID   </option>';
    echo '<option value="option_type"'   , ($s_field == 'option_type'    ? ' selected="selected"' : ''), '> Option Type </option>';
    echo '<option value="option_status"' , ($s_field == 'option_status'  ? ' selected="selected"' : ''), '> Trạng Thái  </option>';
    echo '<option value="option_key"'    , ($s_field == 'option_key'     ? ' selected="selected"' : ''), '> Option Key  </option>';
    echo '<option value="option_data"'   , ($s_field == 'option_data'    ? ' selected="selected"' : ''), '> Option Data </option>';
}

function build_advanced_filter_namhoa_system_option($s_field, $a_hide = array()) {
    if (empty($a_hide)) {
        return build_filter_namhoa_system_option($s_field);
    }

    $a_columns = array(
        'option_id'     => 'Option ID'   ,
        'option_type'   => 'Option Type' ,
        'option_status' => 'Trạng Thái'  ,
        'option_key'    => 'Option Key'  ,
        'option_data'   => 'Option Data' ,
    );

    $a_hide    = array_combine($a_hide, $a_hide);
    $a_columns = array_diff_key($a_columns, $a_hide);

    foreach ($a_columns as $v_columnname => $v_columncomment) {
        echo '<option value="', $v_columnname, '"', ($s_field == $v_columnname ? ' selected="selected"' : ''), '>', $v_columncomment, '</option>';
    }
}
?>